package com.hspedu.qqserver.service;

import com.hspedu.qqcommon.Message;
import com.hspedu.qqcommon.User;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.net.Socket;

/**
 * @author DL5O
 * @version 1.0
 * 该类的一个对象和某个客户端保持一个通讯
 */
public class ServerConnectClientThread extends Thread{

    private Socket socket;
    private String userId;//和哪一个客服端进行通讯

    public ServerConnectClientThread(Socket socket, String userId) {
        this.socket = socket;
        this.userId = userId;
    }

    @Override
    public void run() {//这里线程处于运行状态，用于发送和接受消息
        while(true){
            System.out.println("服务端和客服端 "+ userId +" 保持通讯读取数据...");
            try {
                ObjectInputStream ois = new ObjectInputStream(socket.getInputStream());
                Message mes = (Message) ois.readObject();
                //后面会使用这个mes
            } catch (IOException e) {
                e.printStackTrace();
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }
        }
    }
}
